package com.yida.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yida.service.serverphoto;

@Controller
public class adminPhototype {
	
	@Autowired
	public serverphoto service;
	
	@RequestMapping("/admin/phototype")
	public String photo(Model mode) {
		
	List<com.yida.bean.phototype> phototypes = service.phototype();	
    mode.addAttribute("phototypes", phototypes);
  
      return  "admin/phototype";
	}
	
	
	
	
	@RequestMapping("/admin/phototypedelete")
	@ResponseBody
	public Object photodelete(Model mode,Integer id) throws JsonProcessingException {	
	boolean  result = service.phototypedelete(id);
	
    if (result) {
    	
    	Map<String,String> map = new HashMap<String,String>();
    	map.put("result", "true");
    	ObjectMapper objectMapper = new ObjectMapper();
    	String json = objectMapper.writeValueAsString(map);
        return  json;
    	 
	}else {

    	Map<String,String> map = new HashMap<String,String>();
    	map.put("result", "false");
    	ObjectMapper objectMapper = new ObjectMapper();
    	String json = objectMapper.writeValueAsString(map);
    	 return  json;
	}
		
	}
	
	
//	@Test
//	public void  test1() {
//		
//		new File(System.getProperties().getProperty("user.home")+"/blog/photos/").mkdirs();
//		
//		//System.out.println(System.getProperties().getProperty("user.home"));
//		
//	}
		
		
	
	
	

}
